/*******************************************************************************
 * $Header: /cvsroot/oloa/org.gocom.bpm.platform.model/src/org/gocom/bpm/platform/model/web/taglib/WFHTMLBaseTag.java,v 1.1 2011/07/03 02:30:16 hufulai Exp $
 * $Revision: 1.1 $
 * $Date: 2011/07/03 02:30:16 $
 *
 *==============================================================================
 *
 * Copyright (c) 2001-2006 Primeton Technologies, Ltd.
 * All rights reserved.
 * 
 * Created on 2010-5-26
 *******************************************************************************/

package com.atozsoft.wf.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.eos.web.taglib.util.XpathUtil;

public abstract class WFHTMLBaseTag extends BodyTagSupport {
	protected String id;

	protected String name;

	protected String scope;

	protected String onclick;

	protected String ondblclick;

	protected String onmouseover;

	protected String onmouseout;

	protected boolean readonly;

	protected String style;

	protected String styleClass;

	private Object rootObj;
	
	public WFHTMLBaseTag() {
		id = null;
		name = null;
		scope = null;
		onclick = null;
		ondblclick = null;
		onmouseover = null;
		onmouseout = null;
		readonly = false;
		style = null;
		styleClass = null;
		rootObj = null;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}

	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public String getOndblclick() {
		return ondblclick;
	}

	public void setOndblclick(String ondblclick) {
		this.ondblclick = ondblclick;
	}

	public boolean isReadonly() {
		return readonly;
	}

	public void setReadonly(boolean readonly) {
		this.readonly = readonly;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getStyleClass() {
		return styleClass;
	}

	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}

	public Object getRootObj() {
		return rootObj;
	}

	public void setRootObj(Object rootObj) {
		this.rootObj = rootObj;
	}

	public void initScope() {
		if (scope == null)
			scope = (String) pageContext.getAttribute("scope");
		if (scope == null)
			scope = "request";
		rootObj = XpathUtil.getDataContextRoot(scope, pageContext);
	}

	public void setPageContext(PageContext pageContext) {
		if (pageContext != null)
			this.pageContext = pageContext;
		//VRuleAssemblerFactory.registerVRules();
	}

	public int doEndTag() throws JspException {
		return super.doEndTag();
	}

	public void release() {
		super.release();
	}

	protected String prepareEventHandlers() {
		StringBuffer handlers = new StringBuffer();
		prepareMouseEvents(handlers);
		return handlers.toString();
	}

	protected String prepareEventHandlers(String event, String handler) {
		StringBuffer handlersBuff = new StringBuffer();
		prepareAttribute(handlersBuff, event, handler);
		return handlersBuff.toString();
	}

	protected void prepareMouseEvents(StringBuffer handlers) {
		prepareAttribute(handlers, "onclick", getOnclick());
		prepareAttribute(handlers, "ondblclick", getOndblclick());
	}

	protected String prepareStyles() throws JspException {
		StringBuffer styles = new StringBuffer();
		prepareAttribute(styles, "style", getStyle());
		prepareAttribute(styles, "class", getStyleClass());
		return styles.toString();
	}

	protected void prepareAttribute(StringBuffer handlers, String name,
			Object value) {
		if (value != null) {
			handlers.append(" ");
			handlers.append(name);
			handlers.append("=\"");
			handlers.append(value);
			handlers.append("\"");
		}
	}

	protected String getElementClose() {
		return ">";
	}

	public abstract void initVariables();

	public void validate() throws Exception {
		
	}

	public String getOnmouseout() {
		return onmouseout;
	}

	public void setOnmouseout(String onmouseout) {
		this.onmouseout = onmouseout;
	}

	public String getOnmouseover() {
		return onmouseover;
	}

	public void setOnmouseover(String onmouseover) {
		this.onmouseover = onmouseover;
	}

}
